package com.csx.micrometer.invoke.config;

import com.csx.micrometer.invoke.core.inbound.servlet.MicrometerServletHandlerInboundInterceptor;
import com.csx.micrometer.invoke.custom.TagsCustom;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.List;

/**
 * @author cuisongxu
 * @date 2022/12/1 14:20
 */

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class ServletInboundMicrometerConfiguration {

    @ConditionalOnMissingBean
    @Bean
    public HandlerInterceptor micrometerHandlerInterceptor(List<TagsCustom> tagsCustom) {
        return new MicrometerServletHandlerInboundInterceptor(tagsCustom);
    }
}
